package com.hx.zhg.web.controller.system;

import com.hx.zhg.service.utils.SpringUtil;
import com.hx.zhg.util.JsonUtils;
import com.hx.zhg.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "系统相关接口")
@RestController
@RequestMapping("/system")
public class SystemController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(WxSystemController.class);

    @ApiOperation(value = "查看当前spring容器中的实例", notes = "查看当前spring容器中的实例")
    @RequestMapping(value = "/getInt", method = RequestMethod.GET)
    public String getInt(HttpServletRequest request) {
        String result = "";
        try {
            ApplicationContext applicationContext = SpringUtil.getApplicationContext();
            String[] str = applicationContext.getBeanDefinitionNames();
            result = JsonUtils.objToJson(str);
        } catch (Exception e) {
            log.error(String.format("system throw exception error: %s; HEADERS: %s", getHeaders(request), e));
            return this.retInternalErrorDefault();
        }
        return result;
    }
}
